import os
import json

# 数据集目录
data_dir = './dataset/train'

# 获取所有类别名称
classes = sorted(os.listdir(data_dir))

# 生成类别映射
class_indices = {str(i): cls for i, cls in enumerate(classes)}

# 保存为 JSON 文件
with open('class_indices3.json', 'w') as f:
    json.dump(class_indices, f, indent=4)
